package com.uuah.server.config.spring.parsers.specific;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.uuah.server.config.spring.parsers.AbstractUuahBeanDefinitionParser;
import com.uuah.server.config.spring.parsers.generic.ChildDefinitionParser;

public class ComponentDefinitionParser extends ChildDefinitionParser {

	public ComponentDefinitionParser(Class clazz) {
		super("component", clazz);
		this.singleton = true;
		addIgnored(AbstractUuahBeanDefinitionParser.ATTRIBUTE_CLASS);
	}

	// @Override
	protected void parseChild(Element element, ParserContext parserContext,
			BeanDefinitionBuilder builder) {
		Element parent = (Element) element.getParentNode();
		String serviceName = parent.getAttribute(ATTRIBUTE_NAME);
		builder.addPropertyReference("service", serviceName);
		super.parseChild(element, parserContext, builder);
	}
}
